export default {
  namespaced:true,
  state:{
    seconds: 3,
    timer:null
  },
  mutations:{
    showCountDown(state,n) {
      uni.showToast({
        icon:"none",
        title:'请先登录' + n + '秒后自动跳转登录',
        mask:true,
        duration:2000
      })
    },
    cutSecond(state) {
      state.seconds --
    },
    setTimer(state,timer) {
      state.timer = timer
      
    }
    
  },
  actions: {
    delayNavigate(context) {
      this.seconds = 3
     context.commit('showCountDown',context.state.seconds)
    let timer2  = setInterval(() => {
      context.commit('setTimer',timer2)
       // context.commit.cutSecond()
       context.commit('cutSecond')
       if(context.state.seconds <= 0) {
         clearInterval(context.state.timer)
         uni.switchTab({
           url:'/pages/my/my'
         })
         return
       }
        context.commit('showCountDown',context.state.seconds)
       
     },1000)
    }
    
  }
}